fix clang diagnostic cast-qual (#967)
authortsteven4 <13596209+tsteven4@users.noreply.github.com>
Sat, 31 Dec 2022 12:27:50 +0000 (05:27 -0700)
committerGitHub <noreply@github.com>
Sat, 31 Dec 2022 12:27:50 +0000 (05:27 -0700)
* fix cast-qual clang diagnostic

* use const_cast to cheat

* decay an array with casts.

the assembly code for gpsusbwin and gpsusbcommon does match the master branch.

* explicitly use const with auto*

exif.cc
gui/gpx.h
jeeps/gpsusbcommon.cc
jeeps/gpsusbwin.cc
jeeps/jgpsutil.cc
navilink.cc
skytraq.cc
util.cc
util_crc.cc
wbt-200.cc

diff --git a/exif.cc b/exif.cc
index 956d34ba5dd844b002eec285c512dca6b028aeab..301488fc389355bbc796b6b7763643a37c59f239 100644 (file)
--- a/exif.cc
+++ b/exif.cc
@@ -1032,7 +1032,7 @@ ExifFormat::exif_put_value(const int ifd_nr, const uint16_t tag_id, const uint16
     if (size_increase > 0) {
       qba.append(size_increase, 0);
     }
-    qba.replace(index, count, (char*) data, count);
+    qba.replace(index, count, static_cast<const char*>(data), count);
     tag->data[0] = qba;
   } else {
     // we haven't coded for insertion of multiple values (except for BYTE_TYPE above).
@@ -1041,17 +1041,17 @@ ExifFormat::exif_put_value(const int ifd_nr, const uint16_t tag_id, const uint16
     case EXIF_TYPE_SHORT:
     case EXIF_TYPE_SSHORT:
       tag->grow<uint16_t>(index + count);
-      tag->data[index] = *(uint16_t*)data;
+      tag->data[index] = *static_cast<const uint16_t*>(data);
       break;
     case EXIF_TYPE_LONG:
     case EXIF_TYPE_SLONG:
     case EXIF_TYPE_IFD:
       tag->grow<uint32_t>(index + count);
-      tag->data[index] = *(uint32_t*)data;
+      tag->data[index] = *static_cast<const uint32_t*>(data);
       break;
     case EXIF_TYPE_RAT:
     case EXIF_TYPE_SRAT: {
-      double val = *(double*)data;
+      double val = *static_cast<const double*>(data);
 
       if ((val < 0.0) && (type == EXIF_TYPE_RAT)) {
         fatal(MYNAME ": A negative value cannot be stored as type RATIONAL.");
@@ -1065,11 +1065,11 @@ ExifFormat::exif_put_value(const int ifd_nr, const uint16_t tag_id, const uint16
     break;
     case EXIF_TYPE_FLOAT:
       tag->grow<float>(index + count);
-      tag->data[index] = *(float*)data;
+      tag->data[index] = *static_cast<const float*>(data);
       break;
     case EXIF_TYPE_DOUBLE:
       tag->grow<double>(index + count);
-      tag->data[index] = *(double*)data;
+      tag->data[index] = *static_cast<const double*>(data);
       break;
     default:
       fatal(MYNAME ": Unknown data type %u!\n", type);
index 0096fdd32b2a5b6ec3fa944239795985d3a2d8f7..8d7f1ff215d99bb3fb584b9b3599a01a272b40e0 100644 (file)
--- a/gui/gpx.h
+++ b/gui/gpx.h
@@ -129,8 +129,7 @@ public:
         prevPt = thisPt;
       }
     }
-    auto* dptr = (double*)(&cachedLength);  // big cheat
-    *dptr = dist;
+    *const_cast<double*>(&cachedLength) = dist;  // big cheat
     return cachedLength;
   }
 
@@ -355,8 +354,7 @@ public:
         }
       }
     }
-    auto* dptr = (double*)(&cachedLength);  // big cheat
-    *dptr = dist;
+    *const_cast<double*>(&cachedLength) = dist;  // big cheat
     return cachedLength;
   }
 
index 6c37d0ba3dbd5d3a9be551b29b12674cd158223c..5c91c47607ecb51e2fafb04b046eff700f6d611d 100644 (file)
@@ -153,7 +153,7 @@ top:
 int
 gusb_cmd_send(const garmin_usb_packet* opkt, size_t sz)
 {
-  auto* obuf = (unsigned char*) &opkt->dbuf;
+  const auto* obuf = opkt->dbuf;
   const char* m2;
 
   unsigned int rv = gusb_llops->llop_send(opkt, sz);
@@ -215,7 +215,7 @@ gusb_id_unit(garmin_unit_info_t* gu)
   garmin_usb_packet iresp;
   int i;
 
-  gusb_cmd_send((garmin_usb_packet*)oid, sizeof(oid));
+  gusb_cmd_send(reinterpret_cast<const garmin_usb_packet*>(oid), sizeof(oid));
 
   for (i = 0; i < 25; i++) {
     iresp.gusb_pkt.type = 0;
index 9da6d227d8bd02490a2d2703d7cebecd2991af84..4b5f3e25ab1b6e8c53d888563f9f4b52e97f316e 100644 (file)
@@ -110,7 +110,7 @@ static int
 gusb_win_send(const garmin_usb_packet* opkt, size_t sz)
 {
   DWORD rsz;
-  unsigned char* obuf = (unsigned char*) &opkt->dbuf;
+  const auto* obuf = opkt->dbuf;
 
   /* The spec warns us about making writes an exact multiple
    * of the packet size, but isn't clear whether we can issue
@@ -236,7 +236,7 @@ gusb_init(const char* pname, gpsdevh** dh)
     }
   }
 
-  hdevinfo = SetupDiGetClassDevs((GUID*) &GARMIN_GUID, NULL, NULL,
+  hdevinfo = SetupDiGetClassDevs(&GARMIN_GUID, NULL, NULL,
                                  DIGCF_PRESENT | DIGCF_INTERFACEDEVICE);
 
   if (hdevinfo == INVALID_HANDLE_VALUE) {
@@ -249,7 +249,7 @@ gusb_init(const char* pname, gpsdevh** dh)
 
   if (req_unit_number >= 0) {
     if (!SetupDiEnumDeviceInterfaces(hdevinfo, NULL,
-                                     (GUID*) &GARMIN_GUID,
+                                     &GARMIN_GUID,
                                      req_unit_number, &devinterface)) {
       // If there were zero matches, we may be trying to talk to a "GPX Mode" device.
 
@@ -277,7 +277,7 @@ gusb_init(const char* pname, gpsdevh** dh)
    */
   for (match = 0;; match++) {
     if (!SetupDiEnumDeviceInterfaces(hdevinfo, NULL,
-                                     (GUID*) &GARMIN_GUID, match, &devinterface)) {
+                                     &GARMIN_GUID, match, &devinterface)) {
       if (GetLastError() == ERROR_NO_MORE_ITEMS) {
 
         break;
index 92721fc1ba9bb7997e8b52f60548fb6ca1c707e6..0f522005fb9d7bdb50218c7d2953f804c0db1f42 100644 (file)
@@ -104,9 +104,7 @@ US GPS_Util_Get_Short(const UC* s)
 
 void GPS_Util_Put_Short(UC* s, const US v)
 {
-  UC* p;
-
-  p = (UC*)&v;
+  const auto* p = reinterpret_cast<const UC*>(&v);
 
   if (!GPS_Little) {
     *s++ = *(p+1);
@@ -163,10 +161,9 @@ double GPS_Util_Get_Double(const UC* s)
 
 void GPS_Util_Put_Double(UC* s, const double v)
 {
-  UC* p;
   int32 i;
 
-  p = (UC*)&v;
+  const auto* p = reinterpret_cast<const UC*>(&v);
 
   if (!GPS_Little)
     for (i=sizeof(double)-1; i>-1; --i) {
@@ -225,10 +222,9 @@ int32 GPS_Util_Get_Int(const UC* s)
 
 void GPS_Util_Put_Int(UC* s, const int32 v)
 {
-  UC* p;
   int32 i;
 
-  p = (UC*)&v;
+  const auto* p = reinterpret_cast<const UC*>(&v);
 
   if (!GPS_Little)
     for (i=sizeof(int32)-1; i>-1; --i) {
@@ -286,10 +282,9 @@ uint32 GPS_Util_Get_Uint(const UC* s)
 
 void GPS_Util_Put_Uint(UC* s, const uint32 v)
 {
-  UC*    p;
   int32 i;
 
-  p = (UC*)&v;
+  const auto* p = reinterpret_cast<const UC*>(&v);
 
   if (!GPS_Little)
     for (i=sizeof(uint32)-1; i>-1; --i) {
@@ -347,10 +342,9 @@ float GPS_Util_Get_Float(const UC* s)
 
 void GPS_Util_Put_Float(UC* s, const float v)
 {
-  UC* p;
   int32 i;
 
-  p = (UC*)&v;
+  const auto* p = reinterpret_cast<const UC*>(&v);
 
   if (!GPS_Little)
     for (i=sizeof(float)-1; i>-1; --i) {
index 494bd210b2fac7fba9ea582c588ed387f7e33f1d..4ddf6189cd6dad4e24d0e18b67215e478b01bf88 100644 (file)
@@ -418,7 +418,7 @@ decode_waypoint(const unsigned char* buffer)
   auto* waypt = new Waypoint;
 
   decode_position(buffer + 12, waypt);
-  waypt->shortname = (char*) buffer + 4;
+  waypt->shortname = reinterpret_cast<const char*>(buffer) + 4;
   waypt->icon_descr = icon_table[buffer[28]];
   waypt->SetCreationTime(decode_datetime(buffer + 22));
 
index 691e2b99baced7bfd4b11dc56a23176eb56ca9e4..92f2c5b1af5b11a16a4f1bd95be9277eccfc10de 100644 (file)
@@ -774,7 +774,7 @@ SkytraqBase::process_data_sector(struct read_state* pst, const uint8_t* buf, int
   int plen, ilen;
 
   for (plen = 0; plen < len  &&  buf[plen] != 0xFF; plen += ilen) {
-    ilen = process_data_item(pst, (item_frame*)&buf[plen], len-plen);
+    ilen = process_data_item(pst, reinterpret_cast<const item_frame*>(&buf[plen]), len-plen);
     if (ilen <= 0) {
       fatal(MYNAME ": Error %i while processing data item #%i (starts at %i)\n",
             ilen, pst->tpn, plen);
diff --git a/util.cc b/util.cc
index 5b7ab0ce2386a2eace83c7e494165046bb330d73..a5887ab81533b8629b21b75cb68aed8a0c6fd1e1 100644 (file)
--- a/util.cc
+++ b/util.cc
@@ -767,7 +767,7 @@ endian_read_double(const void* ptr, int read_le)
     p = ptr;
   } else {
     for (int i = 0; i < 8; i++) {
-      r[i] = ((char*)ptr)[7-i];
+      r[i] = static_cast<const char*>(ptr)[7-i];
     }
     p = r;
   }
@@ -794,7 +794,7 @@ endian_read_float(const void* ptr, int read_le)
     p = ptr;
   } else {
     for (int i = 0; i < 4; i++) {
-      r[i] = ((char*)ptr)[3-i];
+      r[i] = static_cast<const char*>(ptr)[3-i];
     }
     p = r;
   }
index daeec5256997b885eb0bda2ae30f6023ec5320f9..640ceaba33674f48ad832c07153c85e04174d8a6 100644 (file)
@@ -69,9 +69,9 @@ unsigned long
 get_crc32(const void* data, int datalen)
 {
   unsigned long crc = 0xFFFFFFFF;
-  const unsigned char* cp = (unsigned char*)data;
+  const unsigned char* cp = static_cast<const unsigned char*>(data);
 
-  while (cp < ((unsigned char*)data + datalen)) {
+  while (cp < (static_cast<const unsigned char*>(data) + datalen)) {
     crc = ((crc >> 8) & 0x00FFFFFF) ^ crc32_table[(crc ^ *cp) &0xFF];
     cp++;
   }
index c90d312f661e8005a88d5d20ef9ce97d3ae12ff0..1324786be30a14140529d82dc6a60a89a9fcd04f 100644 (file)
@@ -236,7 +236,7 @@ static void buf_extend(struct buf_head* h, size_t amt)
 
 static void buf_update_checksum(struct buf_head* h, const void* data, size_t len)
 {
-  auto* cp = (unsigned char*) data;
+  auto* cp = static_cast<const unsigned char*>(data);
 
   db(4, "Updating checksum with %p, %zu, before: %02x ",
      data, len, h->checksum);